import json
import os

# JsonUtil类，接受文件地址作为初始化参数``
class JsonUtil:
    def __init__(self, file_path):
        # 如果当前文件已经存在，则删除
        self.file_path = file_path

        if os.path.exists(file_path):
            os.remove(file_path)

        

    # 读取json文件，返回json对象列表q
    def json_read(self):
        with open(self.file_path, 'r', encoding='utf-8') as f:
            return [json.loads(line) for line in f]

    # 写入json文件，data为json对象
    def json_write(self, data):
        with open(self.file_path, 'a', encoding='utf-8') as f:
            json.dump(data, f, ensure_ascii=False)
            f.write('\n')
